import React, { Component } from 'react';
import { connect } from 'dva';
import PageHeaderWrapper from '@/components/PageHeaderWrapper';
import { Button, Card, Spin } from 'antd';
import router from 'umi/router';
import ContactPage from './ContactPage';
import FooterToolbar from '@/components/FooterToolbar';

@connect(({ accuservicehandle: { contactList }, loading }) => ({
  contactList,
  loading: loading.models.accuservicehandle,
}))
class ContactHistory extends Component {
  constructor(props) {
    super(props);
    this.state = {};
  }

  componentDidMount() {
    const { dispatch, location } = this.props;
    const { sendId } = location.query;
    dispatch({
      type: 'accuservicehandle/addContact',
      payload: { sendId },
    });
  }

  close = () => {
    const { location } = this.props;
    const { pathname } = location;
    const tempUrl = pathname.split('/contactHistory')[0];
    router.push(`${tempUrl}/index`);
  };

  render() {
    const { contactList, loading } = this.props;
    return (
      <PageHeaderWrapper>
        <Spin tip="Loading..." spinning={loading}>
          <Card title="联系记录">
            {contactList.length ? <ContactPage contactList={contactList} /> : '暂无数据'}
          </Card>
        </Spin>
        <FooterToolbar style={{ width: '100%' }}>
          <Button onClick={() => router.goBack()}>返回</Button>
        </FooterToolbar>
      </PageHeaderWrapper>
    );
  }
}

export default ContactHistory;
